package com.bee.剑指offer;

import java.util.Stack;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-04-18
 */
public class 栈的压入和弹出序列 {

    Stack<Integer> stack = new Stack<Integer>();

    public boolean IsPopOrder(int [] pushA,int [] popA) {
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (!stack.isEmpty() && popA[j] == stack.peek()) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }

    public boolean isPop(int [] pushA,int [] popA) {
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (!stack.isEmpty() && stack.peek() == popA[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println();
    }

}
